package cn.cpf.beantest;

import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {

        BeanDefinition personBeanDefinition = configurableListableBeanFactory.getBeanDefinition("person");
        MutablePropertyValues personMutablePropertyValues = personBeanDefinition.getPropertyValues();

        if (personMutablePropertyValues.contains("phone")) {
            personMutablePropertyValues.addPropertyValue("phone", 166818);
        }
        if (personMutablePropertyValues.contains("name")) {
            personMutablePropertyValues.addPropertyValue("name", "陈鹏飞");
        }

    }
}